<template>
  <div class="content">
    <div class="header">
      <span>To：{{ user_to_send.user_name }}</span>

    </div>
    <div class="text">
      <van-field
          v-model="message"
          rows="8"
          autosize
          border
          type="textarea"
          maxlength="250"
          placeholder="请输入邮件内容"
          show-word-limit
          clearable
      />
    </div>
    <div class="footer">
      <van-button type="default" @click="onSend" block>发送</van-button>
    </div>
  </div>
</template>

<script>
import Vue from "vue"
import api from "@/api/api";
import { Toast } from 'vant';

Vue.use(Toast);

export default {
  name: "MailReply",
  data() {
    return {
      user_to_send: {
        user_name: "张三",
        user_id: 1
      },
      message: ""
    }
  },
  methods:{
    onSend(){
      api.sendMail(this.message,this.user_to_send.user_id).then(res=>{
        if (res){
          Toast('发送成功！3秒后返回到邮箱');
          setTimeout(()=>{
            MiniApp.navigateBack({delta:2})
          },3000)
        }
      })
    }
  },
  beforeMount() {
    let that=this
    MiniApp.getStorage({
      key: "mail",
      success(res) {
        let data=res.data
        if (data){
          let mail=JSON.parse(data)
          that.user_to_send.user_name=mail.from_user.nick_name
          that.user_to_send.user_id=mail.from_user.user_id
        }
      }
    })
  }
}
</script>

<style scoped>
.content {
  background: white;
}

.header {
  font-size: 30px;
  margin-top: 30px;
  margin-bottom: 30px;
  margin-left: 20px;
}
</style>